package com.wnxy.sdd.front.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnxy.sdd.front.entity.Course;
import com.wnxy.sdd.front.entity.Order;
import com.wnxy.sdd.front.mapper.OrderMapper;
import com.wnxy.sdd.front.service.ICourseService;
import com.wnxy.sdd.front.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author Jet
 * @since 2023-04-06
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private ICourseService courseService;

    @Override
    public Order createOrder(String courseId) {
        // 根据课程id查询
        Course course = courseService.getById(courseId);

        Order order = new Order();
        order.setCourseId(courseId);
        order.setOrderTime(new Date());
        order.setUserId("100100100");
        order.setPrice(course.getPrice());
        order.setStatus("1");

        this.save(order);
        return order;
    }
}
